//
// Decompiled by Jadx - 982ms
//
package com.nibiru.lanchuer;

import android.app.INibiruVRManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.nibiru.api.ResetApi;
import com.nibiru.launcher3d.db.DBManager;
import com.nibiru.launcher3d.entry.AppData;
import com.nibiru.launcher3d.receiver.AppManagerReceiver;
import com.nibiru.launcher3d.receiver.OnAppStateChangeListener;
import com.nibiru.launcher3d.utils.LauncherHelper;
import com.nibiru.launcher3d.utils.LocalAppManager;
import com.nibiru.launcher3d.utils.LogUtil;
import com.nibiru.launcher3d.utils.MediaManager;
import com.nibiru.launcher3d.utils.StatMonitor;
import com.nibiru.stat.sdk.IStatSDK;
import com.nibiru.vrconfig.IVRDataService;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import x.core.XBaseXRActivity;

public class Lanchuer2DActivity extends XBaseXRActivity implements StatMonitor.OnStatChangeListener, OnAppStateChangeListener {
    private AppEnterReceiver appEnterReceiver;
    private String[] historyTitles;
    private LocalAppManager mAppManager;
    private AppManagerReceiver mAppReceiver;
    private DBManager mDbManager;
    private HomeKeyEventReceiver mHomeKeyEventReceiver;
    private HomeKeyReceiver mHomeKeyReceiver;
    private StatMonitor mStatMonitor;
    private IStatSDK mStatSDK;
    private RequestQueue queue;
    private ResetApi resetApi;
    private ServiceConnection resetServiceConnection;
    private boolean isWifiAvailable = false;
    protected IVRDataService mService = null;
    private ServiceConnection serviceConnection = new Lanchuer2DActivity$2(this);

    /* JADX WARN: Multi-variable type inference failed */
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        boolean gcBySystem = false;
        if (savedInstanceState != null) {
            gcBySystem = savedInstanceState.getBoolean("gcBySystem", false);
        }
        getSharedPreferences("Device", 0).edit().putBoolean("ShowPassword", !gcBySystem).apply();
        LauncherHelper.language = getResources().getConfiguration().locale.getLanguage();
        this.queue = Volley.newRequestQueue(this);
        if (getNibiruVRService() != null) {
            LauncherHelper.isOversea = isStoreOversea();
            String channel = getChannelCode();
            LogUtil.log("channel: " + channel);
            if (LauncherHelper.isOversea) {
                LauncherHelper.CHANNEL_OVERSEA = channel;
            } else {
                LauncherHelper.CHANNEL = channel;
            }
            saveWhiteList();
        } else {
            Intent intent_service = getServiceIntent(null);
            if (intent_service != null) {
                bindService(intent_service, this.serviceConnection, 1);
            }
        }
        if (!TextUtils.isEmpty(LauncherHelper.password)) {
            bindResetService();
        }
        this.mAppManager = LocalAppManager.getInstance(this);
        this.mDbManager = DBManager.getInstance(this);
        stateMonitor();
        this.mAppReceiver = new AppManagerReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.PACKAGE_ADDED");
        filter.addAction("android.intent.action.PACKAGE_REMOVED");
        filter.addDataScheme("package");
        registerReceiver(this.mAppReceiver, filter);
        this.mAppReceiver.registerAppStateChangeListener(this);
        this.appEnterReceiver = new AppEnterReceiver(this, (Lanchuer2DActivity$1) null);
        registerReceiver(this.appEnterReceiver, new IntentFilter("com.nibiru.action.keycode.enter"));
        this.mHomeKeyEventReceiver = new HomeKeyEventReceiver(this, (Lanchuer2DActivity$1) null);
        IntentFilter homeKeyFilter = new IntentFilter();
        homeKeyFilter.addAction("android.intent.action.CLOSE_SYSTEM_DIALOGS");
        registerReceiver(this.mHomeKeyEventReceiver, homeKeyFilter);
        this.mHomeKeyReceiver = new HomeKeyReceiver(this, (Lanchuer2DActivity$1) null);
        IntentFilter homeKeyFilter2 = new IntentFilter();
        homeKeyFilter2.addAction("com.nibiru.intent.action.PRESS_HOMEKEY");
        registerReceiver(this.mHomeKeyReceiver, homeKeyFilter2);
        SharedPreferences preferences = getPreferences(0);
        boolean isFirst = preferences.getBoolean("isFirst", false);
        LogUtil.log("isFirst: " + isFirst);
        if (!isFirst) {
            initHistory();
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("isFirst", true);
            editor.apply();
        }
        this.mStatSDK = IStatSDK.getInstance(this);
        this.mStatSDK.onAppStart("Launcher-Start");
        this.mStatSDK.initStat();
        INibiruVRManager nibiruVRManager = getNVRManagerService();
        if (nibiruVRManager != null) {
            String result = nibiruVRManager.getParameters("nvr_sys_needhelper");
            boolean resultBool = Boolean.valueOf(result).booleanValue();
            if (resultBool) {
                Intent intent = new Intent("android.settings.LANGUAGE_SETTINGS");
                intent.setFlags(0x10000000);
                intent.putExtra("isGuide", true);
                startActivity(intent);
            }
        }
    }

    protected void onSaveInstanceState(Bundle outState) {
        outState.putBoolean("gcBySystem", true);
        super.onSaveInstanceState(outState);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void stateMonitor() {
        this.mStatMonitor = new StatMonitor(this);
        this.mStatMonitor.setListener(this);
        this.mStatMonitor.initMonitor();
    }

    public void saveWhiteList() {
        new Thread((Runnable) new Lanchuer2DActivity$1(this)).start();
    }

    private void bindResetService() {
        this.resetServiceConnection = new Lanchuer2DActivity$3(this);
        Intent intent = new Intent("com.nibiru.action.resetservice");
        intent.setPackage("com.android.nibiru.settings.vr");
        bindService(intent, this.resetServiceConnection, 1);
    }

    public void resetSystem() {
        if (this.resetApi != null) {
            try {
                this.resetApi.systemReset();
                LogUtil.log("resetSystem");
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    private Intent getServiceIntent(String packageName) {
        List<ResolveInfo> mainList = getPackageManager().queryIntentServices(new Intent("com.nibiru.vrdata.service"), 0);
        List<Intent> mMatchIntents = new ArrayList<>();
        if (mainList != null && mainList.size() > 0) {
            for (ResolveInfo info : mainList) {
                if (info != null && info.serviceInfo != null && !TextUtils.isEmpty(info.serviceInfo.name) && (packageName == null || TextUtils.equals(packageName, info.serviceInfo.packageName))) {
                    Intent intent = new Intent("com.nibiru.vrdata.service");
                    intent.setComponent(new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name));
                    intent.putExtra("packageName", info.serviceInfo.packageName);
                    mMatchIntents.add(intent);
                }
            }
        }
        if (mMatchIntents.size() > 0) {
            return mMatchIntents.get(0);
        }
        return null;
    }

    private void initHistory() {
        if (this.historyTitles == null || this.historyTitles.length == 0) {
            try {
                this.historyTitles = getResources().getStringArray(0x7f0b0000);
            } catch (Resources.NotFoundException e) {
                e.printStackTrace();
            }
        }
        AppData app = new AppData();
        String label = this.mAppManager.getAppLabel("com.Nibiru.IceParkour");
        if (label != null) {
            app.setPackageName("com.Nibiru.IceParkour");
            app.setLabel(label);
            app.setAppState(0);
            app.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app);
        }
        String label2 = this.mAppManager.getAppLabel("com.ArchiactInteractive.LamperVR");
        if (label2 != null) {
            AppData app2 = new AppData();
            app2.setPackageName("com.ArchiactInteractive.LamperVR");
            app2.setLabel(label2);
            app2.setAppState(0);
            app2.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app2);
        }
        String label3 = this.mAppManager.getAppLabel("com.Nibiru.TheOutlaw");
        if (label3 != null) {
            AppData app3 = new AppData();
            app3.setPackageName("com.Nibiru.TheOutlaw");
            app3.setLabel(label3);
            app3.setAppState(0);
            app3.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app3);
        }
        String label4 = this.mAppManager.getAppLabel("com.google.android.youtube");
        if (label4 != null) {
            AppData app4 = new AppData();
            app4.setPackageName("com.google.android.youtube");
            app4.setLabel(label4);
            app4.setAppState(0);
            app4.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app4);
        }
        String label5 = this.mAppManager.getAppLabel("com.google.android.youtube.tv");
        if (label5 != null) {
            AppData app5 = new AppData();
            app5.setPackageName("com.google.android.youtube.tv");
            app5.setLabel(label5);
            app5.setAppState(0);
            app5.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app5);
        }
        String label6 = this.mAppManager.getAppLabel("com.aptoide.vrstore");
        if (label6 != null) {
            AppData app6 = new AppData();
            app6.setPackageName("com.aptoide.vrstore");
            app6.setLabel(label6);
            app6.setAppState(0);
            app6.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app6);
        }
        AppData app7 = new AppData();
        app7.setPackageName("com.nibiru.vrfilemanager");
        app7.setLabel(this.historyTitles[4]);
        app7.setAppState(0);
        app7.setLastOpenTime(System.currentTimeMillis());
        this.mDbManager.insertAppData(app7);
        String label7 = this.mAppManager.getAppLabel("com.nibiru.nibiruvrlive");
        if (label7 != null) {
            AppData app8 = new AppData();
            app8.setPackageName("com.nibiru.nibiruvrlive");
            app8.setLabel(label7);
            app8.setAppState(0);
            app8.setLastOpenTime(System.currentTimeMillis());
            this.mDbManager.insertAppData(app8);
        }
        AppData app9 = new AppData();
        app9.setPackageName("com.nibiru.vrtour");
        app9.setLabel(this.historyTitles[2]);
        app9.setAppState(0);
        app9.setLastOpenTime(System.currentTimeMillis());
        this.mDbManager.insertAppData(app9);
        AppData app10 = new AppData();
        app10.setPackageName("com.nibiru.nibiruvrmedia360");
        app10.setLabel(this.historyTitles[1]);
        app10.setAppState(0);
        app10.setLastOpenTime(System.currentTimeMillis());
        this.mDbManager.insertAppData(app10);
        AppData app11 = new AppData();
        app11.setPackageName("com.nibiru.vr.media.pptvos");
        app11.setLabel(this.historyTitles[0]);
        app11.setAppState(0);
        app11.setLastOpenTime(System.currentTimeMillis());
        this.mDbManager.insertAppData(app11);
        AppData app12 = new AppData();
        app12.setPackageName("com.nibiru.vr.media.pptv");
        app12.setLabel(this.historyTitles[0]);
        app12.setAppState(0);
        app12.setLastOpenTime(System.currentTimeMillis());
        this.mDbManager.insertAppData(app12);
    }

    public void onBluetoothStateChanged(int state) {
        if (state == 2) {
            LauncherHelper.bluetoothState = 2;
        } else if (state == 12 || state == 1 || state == 0 || state == 3) {
            LauncherHelper.bluetoothState = 1;
        } else {
            LauncherHelper.bluetoothState = 0;
        }
    }

    public void onNetworkStateChanged(int nettype, int state, int rssi) {
        if (nettype == 1 && state == 0) {
            if (rssi == 0) {
                LauncherHelper.wifiState = 1;
            } else if (rssi == 1) {
                LauncherHelper.wifiState = 2;
            } else if (rssi == 2) {
                LauncherHelper.wifiState = 3;
            } else if (rssi == 3) {
                LauncherHelper.wifiState = 4;
            }
            if (!this.isWifiAvailable) {
                getWhiteList();
                this.isWifiAvailable = true;
                return;
            }
            return;
        }
        LauncherHelper.wifiState = 0;
        this.isWifiAvailable = false;
    }

    public void onBatteryChanged(int state) {
        LauncherHelper.batteryLevelValue = state;
    }

    public void onBatteryPower(boolean state) {
        if (state) {
            LauncherHelper.batteryState = 1;
        } else {
            LauncherHelper.batteryState = 0;
        }
    }

    public void onTFStateChanged(boolean state) {
        if (state) {
            LauncherHelper.sdcardState = 1;
        } else {
            LauncherHelper.sdcardState = 0;
        }
    }

    public void onHeadsetStateChanged(boolean state) {
        LogUtil.log("onHeadsetStateChanged: " + state);
        if (state) {
            LauncherHelper.headsetState = 1;
        } else {
            LauncherHelper.headsetState = 0;
        }
    }

    public void onSoundStateChanged(boolean state) {
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void onDestroy() {
        super.onDestroy();
        if (this.mStatMonitor != null) {
            this.mStatMonitor.finishMonitor();
        }
        if (this.mAppReceiver != null) {
            this.mAppReceiver.unregisterAppStateChangeListener(this);
            unregisterReceiver(this.mAppReceiver);
        }
        if (this.appEnterReceiver != null) {
            unregisterReceiver(this.appEnterReceiver);
        }
        if (this.mHomeKeyEventReceiver != null) {
            unregisterReceiver(this.mHomeKeyEventReceiver);
        }
        if (this.mHomeKeyReceiver != null) {
            unregisterReceiver(this.mHomeKeyReceiver);
        }
        if (this.mService != null) {
            unbindService(this.serviceConnection);
            this.serviceConnection = null;
        }
        if (this.mStatSDK != null) {
            this.mStatSDK.onAppClose("Launcher-Close");
            this.mStatSDK.onStop();
        }
        if (this.resetServiceConnection != null) {
            unbindService(this.resetServiceConnection);
            this.resetServiceConnection = null;
        }
        MediaManager.getInstance(this).release();
    }

    public void onResume() {
        super.onResume();
        LauncherHelper.language = getResources().getConfiguration().locale.getLanguage();
        LauncherHelper.country = getResources().getConfiguration().locale.getCountry();
    }

    public void onAppStateChanged(String packageName, boolean isInstall) {
        LogUtil.log(packageName + ", " + isInstall);
        LauncherHelper.packageName = packageName;
        if (isInstall) {
            if (this.mAppManager != null) {
                this.mAppManager.updateData(packageName);
            }
            LauncherHelper.appState = 1;
            return;
        }
        LauncherHelper.appState = 2;
        LauncherHelper.isOpenApp = true;
    }

    private void getWhiteList() {
        String url;
        if (LauncherHelper.isOversea) {
            url = "http://playos.1919game.net:8080/NibiruPlay/vr/WhiteAppListAction?version=51&channel=" + LauncherHelper.CHANNEL_OVERSEA;
        } else {
            url = "http://play.1919game.net:8080/NibiruPlay/vr/WhiteAppListAction?version=51&channel=" + LauncherHelper.CHANNEL;
        }
        LogUtil.log("isOversea: " + LauncherHelper.isOversea + ", " + url);
        JsonObjectRequest request = new JsonObjectRequest(url, (JSONObject) null, new Lanchuer2DActivity$4(this), new Lanchuer2DActivity$5(this));
        this.queue.add(request);
    }
}
